#!/bin/bash

src_dir="src"
namespace_name="nut"

#ns=$(echo $namespace_name|awk '{print tolower($0)}')
Ns="Nut"
NS=$(echo $namespace_name|awk '{print toupper($0)}')


create_sub_folder=true

exec 3< <(egrep -o "class\s${NS}_EXPORT\s(\S+)"  "../$src_dir" -R 2>&1)

pattern="\.\.\/$src_dir\/([a-z]+)\.h\:class\s${NS}_EXPORT\s(\w+)"

echo "" > "$Ns"
echo "" > "$ns.h"

if [[ -z create_sub_folder ]]; then
    mkdir -p $Ns
fi

while read line; do
	if [[ $line =~ $pattern ]]; then
		header=${BASH_REMATCH[1]}
		class=${BASH_REMATCH[2]}
		
		echo "#include \"../$src_dir/$header.h\"" > $class
		echo "#include \"../$src_dir/$header.h\"" > "$header.h"

        if [[ -z create_sub_folder ]]; then
            echo "#include \"../$src_dir/$header.h\"" > "$Ns/$class"
            echo "#include \"../$src_dir/$header.h\"" > "$Ns/$header.h"
        fi

		echo "#include \"../$src_dir/$header.h\"" >> "$Ns"
		echo "#include \"../$src_dir/$header.h\"" >> "$ns.h"
	fi
	echo $Ns
done <&3
exec 3<&-
